package com.example.Gallery;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class HelloGallery extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.browser);
        
        Gallery g = (Gallery)findViewById(R.id.gallery);
        
        g.setAdapter(new ImageAdapter(this));

        g.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView parent, View v, int position, long id) {
                Toast.makeText(HelloGallery.this, "" + position, Toast.LENGTH_SHORT).show();
            }
        });
        
        g.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            public void  onItemSelected  (AdapterView<?>  parent, View  v, int position, long id) {
                Animation grow = AnimationUtils.loadAnimation(HelloGallery.this, R.anim.grow);

                View sideView = parent.findViewById(position - 1);
                if (sideView != null)
                   ((ImageView)sideView).setLayoutParams(new Gallery.LayoutParams(150, 100));

                sideView = parent.findViewById(position + 1);
                if (sideView != null)
                   ((ImageView)sideView).setLayoutParams(new Gallery.LayoutParams(150, 100));

                v.startAnimation(grow);
                v.setLayoutParams(new Gallery.LayoutParams(370, 350));
            }

            public void  onNothingSelected  (AdapterView<?>  parent) {
                System.out.println("NOTHING SELECTED");

            }
            });
        
        
    }
}